package Gui;

import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Font;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.border.EmptyBorder;

import DB.UserConnector;
import DB.topScorer;

@SuppressWarnings("serial")
public class highScoresFrame extends JFrame {

	private JPanel contentPane;
	private final JTextArea textArea;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					highScoresFrame frame = new highScoresFrame();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public highScoresFrame() {
		setTitle("HIGH SCORES TABLE");
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JPanel panel = new BackgroundPanel("/black.png",false);
		panel.setBounds(0, 0, this.getWidth(), this.getHeight());
		contentPane.add(panel);
		
		textArea = new JTextArea();
		textArea.setEditable(false);
		textArea.setForeground(new Color(124, 252, 0));
		textArea.setFont(new Font("Old English Text MT", Font.PLAIN, 20));
		textArea.setOpaque(false);
		GroupLayout gl_panel = new GroupLayout(panel);
		gl_panel.setHorizontalGroup(
			gl_panel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel.createSequentialGroup()
					.addGap(42)
					.addComponent(textArea, GroupLayout.PREFERRED_SIZE, 335, GroupLayout.PREFERRED_SIZE)
					.addContainerGap(73, Short.MAX_VALUE))
		);
		gl_panel.setVerticalGroup(
			gl_panel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel.createSequentialGroup()
					.addGap(19)
					.addComponent(textArea, GroupLayout.PREFERRED_SIZE, 234, GroupLayout.PREFERRED_SIZE)
					.addContainerGap(47, Short.MAX_VALUE))
		);
		panel.setLayout(gl_panel);
	
	

				textArea.setText("");
				topScorer[]  topScores= UserConnector.getInstance().getTopPlayers(10);
			/*	ArrayList<WebPlayer>  players=new ArrayList<WebPlayer>(10);//for testing purposes
				for (int j=0;j<10;j++){//for testing purposes
				WebPlayer a=new WebPlayer("tom"+j);//for testing purposes
				a.score=10*j;//for testing purposes
				players.add(j,a);}//for testing purposes
				*/
				if (topScores!= null){
				
				int i=0;
				textArea.setText("Ranking \t Player \t Score \n");
				for (topScorer p: topScores){
					if (p == null ){
						break;
					}
					textArea.setText(textArea.getText()+(i+1)+"\t"+p.name+"\t"+p.score+"\n");
					i++;				}
	

			

			

		}

		/*
		 * Executed in event dispatching thread
		 */

	}
}
